extends Control

var bar = load("res://scene/play/select/select.tscn")
var items = []
var select_info = []

func _ready():
	Model.select = self
	pass

func setSelects(info : Array):
	# info: [{title, tag}]
	clear()
	for v in info:
		var view = bar.instance()
		view.setTitle(v.title)
		view.setTag(v.tag)
		add_child(view)
		items.append(view)
	setSelectsPostion()
	select_info = info
		
func setSelectsPostion():
	var height = 100
	var size = OS.window_size
	var beginY = (size.y * 0.9 - items.size() * height) * 0.5
	for v in items:
		v.position = Vector2(size.x*0.5, beginY)
		beginY += height
	
func clear():
	for v in items:
		remove_child(v)
		v.queue_free()
	items.clear()
	select_info.clear()
	
func working():
	return items.size() != 0
	
func getSaveData():
	return select_info
	
func setSaveData(data : Array):
	setSelects(data)
	if data.size() != 0:
		# 如果分支存在
		Model.dialog.click()
